package com.sophialex.health.record.action;

import org.eclipse.jface.action.Action;
import org.eclipse.swt.SWT;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;

import com.sophialex.health.common.platform.SuperContext;
import com.sophialex.health.person.vo.HrIssue;
import com.sophialex.health.person.vo.HrPerson;
import com.sophialex.health.record.Messages;
import com.sophialex.health.record.dialog.HrIssueDialog;
import com.sophialex.health.record.views.PersonBottomLeftView;
import com.sophialex.health.system.frame.dialog.DialogManager;
/**
 * 问题目录操作类  --- 新增
 * <p>Title:Health</p>
 * <p>HrIssueAction</p>
 * 
 * Alex Apr 18, 2011 9:09:17 PM create
 * @author <a href='wanghao924@126.com'>Alex</a>
 * QQ: 873987060;
 * @version 1.0
 */
public class HrIssueAddAction extends Action implements IWorkbenchAction {
    public static final String ID = "com.sophialex.health.record.action.HrIssueAction";
    
    private IWorkbenchWindow workbenchWindow;
    private PersonBottomLeftView view;
    
    
    public HrIssueAddAction(IWorkbenchWindow workbenchWindow,PersonBottomLeftView view){
    	if(workbenchWindow==null){
    		throw new IllegalArgumentException();
    	}
    	this.view = view;
    	this.workbenchWindow = workbenchWindow;
    	setId(ID);
    	setText(Messages.getString("HrIssueAction.0"));
    	setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_ADD));
    }
    
	public void dispose() {
		workbenchWindow = null;
	}
	
	public void run(){
		if(workbenchWindow == null){
			return;
		}
		HrPerson currentPerson = SuperContext.currentPerson;
		if(currentPerson == null){
			DialogManager.invokeWarnDlg(Messages.getString("Common.12"));
			return;
		}
		HrIssueDialog dlg = new HrIssueDialog(workbenchWindow.getShell(), SWT.NONE);
		HrIssue t = (HrIssue) dlg.open();
		if (t != null) {
            view.refreshAdd(t);
		}
	}

}
